<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/8/23
 * Time: 12:08
 */
class 多关键字搜索
{

}
if(count($newstr)==1){                  //如果数组的元素个数为1个，则按单个条件进行查询
    $sql = "select * from tb_info where title like '%".$newstr[0]."%' or content like '%".$newstr[0]."%'order by id desc ";
}else{

    //合并查询结果集
    for($i=0;$i<count($newstr);$i++){
        $sql0.=" title like '%".trim($newstr[$i])."%'"." or";
    }
    for($j=0;$j<count($newstr);$j++){
        $sql1.=" content like '%".trim($newstr[$j])."%'"." or";
    }
    $sql1=substr($sql1,0,-3);               //去掉最后一个“or”
    $sql="select * from tb_info where".$sql0.$sql1." order by id desc";